import React, { Component } from 'react';

interface IProps {
  flag: boolean;
  children?: any;
}
interface IStatus {
  children: any;
}

class ErrorBoundary extends Component<IStatus, IProps> {
  static getDerivedStateFromError() {
    return {
      flag: true,
    };
  }
  constructor(props: IStatus) {
    super(props);
    this.state = {
      flag: false,
    };
  }

  render() {
    return (
      <div>
        {this.state.flag ? (
          <h1>网络异常，请稍后再试！</h1>
        ) : (
          this.props.children
        )}
      </div>
    );
  }
}

export default ErrorBoundary;
